#include "Background.h"
#include <time.h>
#include <iostream>
#include <sstream>
#include "stdafx.h"

Background::Background(void)
{
	background = sf::Color::Black;
	transitioning = false;
	fading = false;
}


Background::~Background(void)
{
}

void Background::transition(float time, sf::Color trgt)
{
	startTime = clock();
	transitioning = true;
	transitionTime = time;
	target = trgt;
	previous = background;
}

sf::Color Background::getBackground()
{
	if (transitioning)
	{
		clock_t endTime = clock();


		double diff = (((double)endTime) - ((double)startTime))/CLOCKS_PER_SEC;

		if (diff >= std::abs(transitionTime))
		{
			background = target;
			transitioning = false;
			transitionTime = 0;
		}
		else
		{
			double stepR = (target.r-previous.r) /std::abs(transitionTime);
			double stepG = (target.g-previous.g) /std::abs(transitionTime);
			double stepB = (target.b-previous.b) /std::abs(transitionTime);

			background = sf::Color(stepR*diff, stepG*diff, stepB*diff);
		}
	}
	return background;
}





sf::Color Background::getTextColour()
{
	int r = 255-background.r;
	int g = 255-background.g;
	int b = 255-background.b;
	return sf::Color(r, g, b);

}


